import 'package:flutter/cupertino.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:photo_frame/mixin/auto_hide_loading.dart';

abstract class AbsLifecycleState<T extends StatefulWidget> extends State<T>
    with WidgetsBindingObserver, AutoHideLoading {
  @override
  void initState() {
    super.initState();
    Future.value("").then((_) => onResume());
    WidgetsBinding.instance.addObserver(this as WidgetsBindingObserver);
  }

  @override
  void dispose() {
    WidgetsBinding.instance.removeObserver(this as WidgetsBindingObserver);
    super.dispose();
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    print("didChangeAppLifecycleState ${state}");
    switch (state) {
      case AppLifecycleState.resumed:
        onResume();
        break;
      case AppLifecycleState.inactive:
        onInactive();
        break;
      case AppLifecycleState.paused:
        onPause();
        break;
      case AppLifecycleState.detached:
        onDetached();
        break;
      case AppLifecycleState.hidden:
    }
  }

  void onResume() {
  }

  void onInactive() {
    EasyLoading.dismiss();
  }

  void onPause() {
    EasyLoading.dismiss();
  }

  void onDetached() {
    EasyLoading.dismiss();
  }
}
